package model

import (
	"mlgmd.com/hearsay/base"
	"xorm.io/xorm"
)

var DB = &Engine{base.DB}

type Query interface {
	Table(tableNameOrBean interface{}) *xorm.Session
	Where(query interface{}, args ...interface{}) *xorm.Session
	ID(id interface{}) *xorm.Session
	In(column string, args ...interface{}) *xorm.Session
}

type Engine struct {
	*xorm.Engine
}

func (e *Engine) Table(tableNameOrBean interface{}) *xorm.Session {
	return e.Engine.Table(tableNameOrBean)
}

func (e *Engine) Where(query interface{}, args ...interface{}) *xorm.Session {
	return e.Engine.Where(query, args...)
}

func (e *Engine) ID(id interface{}) *xorm.Session {
	return e.Engine.ID(id)
}

func (e *Engine) In(column string, args ...interface{}) *xorm.Session {
	return e.Engine.In(column, args...)
}

type Session struct {
	*xorm.Session
}

func (s *Session) Table(tableNameOrBean interface{}) *xorm.Session {
	return s.Session.Table(tableNameOrBean)
}

func (s *Session) Where(query interface{}, args ...interface{}) *xorm.Session {
	return s.Session.Where(query, args...)
}

func (s *Session) ID(id interface{}) *xorm.Session {
	return s.Session.ID(id)
}

func (s *Session) In(column string, args ...interface{}) *xorm.Session {
	return s.Session.In(column, args...)
}
